home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ldb.zip / BDRDEM1.CPP < prev    next >
C/C++ Source or Header  |  1991-10-18  |  1KB  |  70 lines

  1.     // bdrdem1.cpp
  2.     // Demo of the two Binder constructors
  3.     // Link with binder.obj
  4.     
  5.     // Think of a Binder as an elastic array of void
  6.     // pointers.  The array can be accessed 
  7.     // interchangeably as a stack-queue-deque-list.
  8.  
  9.     #include <string.h>    
  10.     #include <iomanip.h>
  11.     #include "binder.hpp"
  12.  
  13.  
  14.     char *V[] = {
  15.         "Now is the time",
  16.         "for all programmers",
  17.         "to stop reinventing",
  18.         "the linked list!",
  19.         0
  20.     };
  21.     
  22.     void display(char *S)
  23.         { cout << S << endl; }
  24.  
  25.  
  26.     main()
  27.     {
  28.         Binder B1;
  29.  
  30.         for (int i = 0; B1.insQ(V[i]); i++);
  31.  
  32.         cout << "\n\nQueued vector:\n\n";
  33.  
  34.         while (B1.next())    // walk the list
  35.             cout << (char *)(voiD) B1 << endl;
  36.         
  37.         cout << "\n\nPress enter to continue ... ";
  38.         cin.get();
  39.         
  40.         
  41.         
  42.         BindeR B2 = new
  43.             Binder(BDR_OK_FREE,3);
  44.         
  45.         for (i = 0; B2->insQ(strdup(V[i])); i++);
  46.         
  47.         cout << "\n\nQueued cloned vector "
  48.             << "limited to 3 nodes:\n\n";
  49.         
  50.         B2->forEach((BDRforEachBlocK)display);
  51.         
  52.         delete B2;
  53.         
  54.  
  55.  
  56.         Binder B3((voiDV)V);
  57.  
  58.         cout << "\n\nVector exploded into a binder:\n\n";
  59.         
  60.         while (B3++)    // iterate over the list
  61.             cout << (char *) B3.current() << endl;
  62.  
  63.         cout << "\n\nPress enter to quit ... ";
  64.         cin.get();
  65.  
  66.  
  67.  
  68.         return 0;
  69.     }
  70.